Import jmd.rad

Global velY:Float = 0
Global gravityForce:Float = -0.5
Global posY:Float = 0
Global posX:Float
Global velX:Float
Global ballDiameter:Int = 50

Graphics 640,480
SeedRnd MilliSecs()
init()
While Not KeyDown(KEY_ESCAPE)
	
	
	If velY<>0
	'calculate gravity forces
	velY:- gravityForce
	EndIf
	'air friction
	velX:* 0.99 'hack-ish friction
	
	'add acceleration to postion
	posY:+ velY
	posX:+ velX

	'Rebound!
	If posY>GraphicsHeight()-ballDiameter
		posY=GraphicsHeight()-ballDiameter
		velY=Rebound(velY,0.75,0.1)
	EndIf
	If PosX<0
		posX=0
		velX=Rebound(velX,0.75,0.1)
	EndIf
	If posX>GraphicsWidth()-ballDiameter
		posX=GraphicsWidth()-ballDiameter
		velX=Rebound(velX,0.75,0.1)
	EndIf
	
	'Reset?
	If KeyHit(KEY_R)
		Init()
	EndIf
	
	'Draw it
	Cls
	DrawText "Press R to reset",10,10
	DrawOval posX,posY,ballDiameter,ballDiameter
	Flip

Wend

Function init()
	PosX=GraphicsWidth()/2
	velX=Rnd(-15,15)
	posY=0
	velY=0.001
End Function